package com.hanrui.android.fragment.message.audit;

import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hanrui.android.R;
import com.hanrui.android.activity.message.audit.AskForLeaveActivity;
import com.hanrui.android.activity.message.audit.BusinessTravelActivity;
import com.hanrui.android.activity.message.audit.CarActivity;
import com.hanrui.android.activity.message.audit.ChapterApprovalActivity;
import com.hanrui.android.activity.message.audit.ContractActivity;
import com.hanrui.android.activity.message.audit.DispatchDocActivity;
import com.hanrui.android.activity.message.audit.EmpQuitActivity;
import com.hanrui.android.activity.message.audit.GuaranteeContractActivity;
import com.hanrui.android.activity.message.audit.IssueActivity;
import com.hanrui.android.activity.message.audit.MeetingIssueActivity;
import com.hanrui.android.activity.message.audit.OfficeGoodActivity;
import com.hanrui.android.activity.message.audit.OverSeeMonthActivity;
import com.hanrui.android.activity.message.audit.OverSeeThreeActivity;
import com.hanrui.android.activity.message.audit.PerformanceActivity;
import com.hanrui.android.activity.message.audit.ProBusInfoActivity;
import com.hanrui.android.activity.message.audit.ProEleBidInfoActivity;
import com.hanrui.android.activity.message.audit.ProEleWeeklyMainActivity;
import com.hanrui.android.activity.message.audit.ProposalActivity;
import com.hanrui.android.activity.message.audit.ProposalVoteActivity;
import com.hanrui.android.activity.message.audit.ReceiptDocActivity;
import com.hanrui.android.activity.message.audit.SealBorrowActivity;
import com.hanrui.android.activity.message.audit.WorkOverTimeActivity;
import com.hanrui.android.activity.message.audit.YearPlanActivity;
import com.hanrui.android.adapter.ApproveAdapter;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.ApproveListBean;
import com.hanrui.android.net.contract.message.audit.ApproveContract;
import com.hanrui.android.net.presenter.message.audit.ApprovePresenter;
import com.hanrui.android.widget.SearchEditText;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * 代办提醒列表
 *
 */

public class ApproveFragment extends BaseFragment<ApprovePresenter> implements ApproveContract.View {

    @BindView(R.id.searchEditText)
    SearchEditText searchEditText;
    @BindView(R.id.recyclerview_swipeLayout)
    SwipeRefreshLayout swipeLayout;
    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    @Inject
    ApproveAdapter adapter;


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_audit;
    }

    @Override
    protected void initInjector() {
        mFragmentComponent.inject(this);
    }

    @Override
    protected void initView(View view) {
        init();
    }


    public void init() {

        swipeLayout.setColorSchemeColors(ContextCompat.getColor(getActivity(),R.color.c_2795ff));
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                mPresenter.refresh(getActivity());
            }
        });


        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.setAdapter(adapter);
        adapter.setEmptyView(getNoDataView(mRecyclerView));
        adapter.setEnableLoadMore(false);

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ApproveListBean.ActListBean bean = (ApproveListBean.ActListBean) adapter.getItem(position);
                String key = bean.getProcDefInfoKey();
                String taskId = bean.getTaskId();
                String procInsId = bean.getProcInsId();
                String bizId = bean.getVars().getMap().getBusinessId();

                switch (key) {
                    case "process_law_guarantee_contract":
                        //担保合同
                        GuaranteeContractActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_seal_borrow":
                        //借章
                        SealBorrowActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_car_apply":
                        //用车
                        CarActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_seal_use":
                    case "process_oa_seal_use_b":
                    case "process_oa_seal_use_c":
                    case "process_oa_seal_use_d":
                    case "process_oa_seal_use_e":
                    case "process_seal_finance_use":
                        //用章
                        ChapterApprovalActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_business_travel":
                        //出差
                        BusinessTravelActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_overtime":
                        //加班
                        WorkOverTimeActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_office_goods_apply":
                        //办公用品
                        OfficeGoodActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_emp_leave":
                        //请假
                        AskForLeaveActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_proposal":
                        //董事会议案
                        ProposalActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_directorate":
                        //董事会表决
                        ProposalVoteActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_emp_quit":
                        //离职
                        EmpQuitActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_meeting_issue_apply":
                        //会议议题
                        MeetingIssueActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_finance_meeting_issue_capital":
                    case "process_finance_meeting_issue_risk":
                        //资金会、风审会
                        IssueActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_receipt":
                        //收文
                        ReceiptDocActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_pro_task_book_management":
                        //任务书
                        ProBusInfoActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_pro_bidding_management":
                        //编标招标
                        ProEleBidInfoActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_pro_contract_management_gt":
                        //合同
                        ContractActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_pro_project_schedule":
                        //周报
                        ProEleWeeklyMainActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_oversee_key_overview":
                        //三色督办
                        OverSeeThreeActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_emp_performance_appraisal_apply":
                        //绩效
                        PerformanceActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_emp_performance_year_plan":
                        //年度绩效
                        YearPlanActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oa_dispatch":
                        //发文
                        DispatchDocActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    case "process_oversee_month_send":
                        //月督办
                        OverSeeMonthActivity.start(getActivity(),taskId,procInsId,bizId);
                        break;
                    default:
                        ToastUtils.showShort("开发中...");
                        break;
                }

            }
        });

    }

    @Override
    public void onResume() {
        super.onResume();
        swipeLayout.setRefreshing(true);
        mPresenter.refresh(getActivity());
    }

    @Override
    public void loadData(List<ApproveListBean.ActListBean> dataList, int loadType) {

        setLoadDataResult(swipeLayout,adapter,dataList,loadType,false);
    }

}
